package com.guigu.health.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.health.dao.CheckItemMapper;
import com.guigu.health.pojo.CheckItem;
import com.guigu.health.pojo.CheckItemExample;
import com.guigu.health.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName:CheckItemImpl
 * @Description:CheckItem业务接口实习类
 * @Author:longtao
 * @Date:2021/4/14
 * @Version:1.0
 */
@Service(value = "checkItemService")
public class CheckItemServiceImpl implements CheckItemService {
    private CheckItemMapper checkItemMapper;
    @Autowired
    @Qualifier(value = "checkItemMapper")
    public void setCheckItemMapper(CheckItemMapper checkItemMapper) {
        this.checkItemMapper = checkItemMapper;
    }

    @Override
    public PageInfo<CheckItem> queryAllCheckItem(CheckItemExample name, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<CheckItem> list = checkItemMapper.selectByExample(name);
        PageInfo<CheckItem> pageInfo=new PageInfo<CheckItem>(list);
        return pageInfo;
    }

    @Override
    public boolean updateCheckItem(CheckItem checkItem, CheckItemExample example) {
        boolean flag=false;
        int i = checkItemMapper.updateByExampleSelective(checkItem, example);
        if (i>0){
            flag=true;
        }
        return flag;
    }

    @Override
    public boolean deleteCheckItem(Integer id) {
        boolean flag=false;
        /**
         * 删除它与检查组中的关系
         */
        checkItemMapper.deleteCheckGroupKey(id);

        int i = checkItemMapper.deleteByPrimaryKey(id);
        if (i>0){
            flag=true;
        }
        return flag;
    }

    @Override
    public boolean addCheckItem(CheckItem item) {
        boolean flag=false;
        int i = checkItemMapper.insert(item);
        if (i>0){
            flag=true;
        }
        return flag;
    }

    @Override
    public List<CheckItem> querAll() {
        List<CheckItem> list = checkItemMapper.selectByExample(null);
        return list;
    }

    /**
     * 编码名不一致
     *
     * @param code
     * @return
     */
    @Override
    public int count(String code) {
        return checkItemMapper.count(code);
    }
}
